package http_server_init

import (
	"fmt"
	"github.com/gin-gonic/gin"
	"go_server/game_server/api/http/player"
	"go_server/game_server/api/http/system"
	"go_server/zinx/zconf"
	"go_server/zinx/zlog"
	"io"
)

func StartHttpServer() {
	go startServer()
	zlog.Ins().InfoF("[START] HTTP Server name: %s,listener at IP: %s, Port %d is starting",
		zconf.GlobalObject.Name, zconf.GlobalObject.Host, zconf.GlobalObject.HttpPort)
}

func startServer() {
	gin.SetMode(gin.ReleaseMode)
	gin.DefaultWriter = io.Discard
	router := gin.Default()

	router.GET("/sys/reloadConfig", system.ReloadConfig)
	router.GET("/sys/onlineCount", system.PlayerOnlineCount)
	router.GET("/sys/kickOutPlayer", system.KickoutPlayer)
	router.GET("/sys/kickOutAllPlayer", system.KickoutAllPlayer)

	router.GET("/player/getPlayerBagItems", player.GetBagItems)
	router.POST("/player/removePlayerBagItems", player.RemoveBagItems)
	router.POST("/player/addPlayerBagItems", player.AddBagItems)

	router.Run(zconf.GlobalObject.Host + ":" + fmt.Sprint(zconf.GlobalObject.HttpPort))
}
